<?php

namespace app\controllers;

use app\controllers\action\Teacher;
use app\controllers\action\Student;
use core\controller\Controller;
use db\Conn;

class get_student_grade implements Controller
{
    public static function execute()
    {
        $return = ["code" => 400, "data" => [], "msg" => "获取学生成绩失败"];
        /* @var \mysqli $conn */
        $conn = Conn::execute();
        if ($_SESSION["user_type"] == "teacher") {
            $return["data"] = Teacher::get_student_grade($conn, $_GET["student_name"], $_GET["min"], $_GET["max"]);
            $return["code"] = 200;
            $return["msg"] = "获取学生成绩成功";
        } else if ($_SESSION["user_type"] == "student") {
            $return["data"] = Student::get_self_grade($conn, $_SESSION["student_id"]);
            $return["code"] = 200;
            $return["msg"] = "获取学生成绩成功";
        }

        $conn->close();

        return $return;
    }
}